var  Q = require('q'),
	http = require('http'),
	qs = require('querystring'),
	_ = require('lodash');


exports.CreateRcvRecord=function(){
	
}

exports.CreteDoc=function(key, records, callBackFun){
	var ParamIn = [];

    _.forEach(records, function (record) {
        var param;
        var docList = [];
        docList.push(record.CreateDocJSON);
        param.DocTypeEnum = record.DocType;
        param.DocDetialJson=docList;

        ParamIn.push(param);
    });

    var context = {
		CultureName: "zh-CN",
		EntCode: "1",
		OrgCode: "0001",
		UserCode: "demo"
	};

	var CreatedDocKey = key

	var params = {
		context: context,
		ParamIn: ParamIn,
		CreatedDocKey: CreatedDocKey
	};

	var options = {  
    	hostname: 'lwd',
    	port: 80,  
    	path: 'U9/RestServices/UFIDA.U9.ISV.QXCompleteSV.QX.ICreateCompleteSV.svc/Do',  
    	method: 'POST',
    	headers: {
        	'Content-Type': 'application/json'
    	}
	}; 

	var params=JSON.stringify(params);

	var req=http.request(options, function (res) {
	    re.setEncoding('utf8');
	    re.on('data', function (res) {
	        callBackFun&&callBackFun(null, "OK");
	    }).on('end', function (res) {
    		console.log(res.body);
    	})
	}).on('error', function (err) {
	    callBackFun&&callBackFun(err);
	})
    
	req.write(params); 
	req.end();
}